﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StarClub.BLL;

namespace StarClub.Web.Admin
{
    public partial class MessageList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.UCFootSeach1.Seach += new EventHandler(UCFootSeach1_Seach);
            if (!IsPostBack)
            {
                Bind();
            }
        }
        void Bind()
        {
            star_message bll = new star_message();
            ListView1.DataSource = bll.GetMessageList(this.UCFootSeach1.SeachText);
            ListView1.DataBind();
            this.ul_SelectDate.Visible = (this.DataPager1.TotalRowCount > 0);
            this.div_DataPager.Visible = (this.DataPager1.TotalRowCount > 0);
        }
        protected void UCFootSeach1_Seach(object sender, EventArgs e)
        {
            Bind();
        }
        //ListView分页
        protected void ListView1_PagePropertiesChanged(object sender, EventArgs e)
        {
            int PageSize = this.DataPager1.PageSize;
            int StartRowIndex = this.DataPager1.StartRowIndex;
            this.DataPager1.SetPageProperties(StartRowIndex, PageSize, true);
            Bind();
        }
        //跳转到第几页
        protected void btnGoPage_Click(object sender, EventArgs e)
        {
            int PageSize = this.DataPager1.PageSize;
            int pageNum;
            if (!int.TryParse(this.txbPageNum.Text, out pageNum) || pageNum < 1)
            {
                Common.MessageBox.Show(Page, "请输入正确的页码");
                return;
            }
            int StartRowIndex = this.DataPager1.StartRowIndex;
            int TotalPageCount = (int)Math.Ceiling((double)DataPager1.TotalRowCount / DataPager1.PageSize);
            if (pageNum >= TotalPageCount)
                StartRowIndex = (TotalPageCount - 1) * PageSize;
            else
                StartRowIndex = (pageNum - 1) * PageSize;
            this.DataPager1.SetPageProperties(StartRowIndex, PageSize, true);
            Bind();
        }
    }
}
